﻿using System.Collections.Generic;
using OpenLS.Drawing;

namespace OpenLS.Spreadsheet.Formats.Biff
{
    class PictureContext
    {
        Dictionary<XamlElement, Picture> _contentToPictureTable = new Dictionary<XamlElement, Picture>();
        public Picture GetPicture (object content)
        {
            if (content is Picture)
                return (Picture) content;
            if (content is XamlElement)
            {
                XamlElement element = (XamlElement) content;
                Picture result;
                if (!_contentToPictureTable.TryGetValue(element, out result))
                {
                    result = element.ToPicture();
                    _contentToPictureTable.Add(element, result);
                }
                return result;
            }
            return null;
        }
    }
}